--- import BlogCard from '@/components/BlogCard.astro' import Breadcrumbs from '@/components/Breadcrumbs.astro' import Container from '@/components/Container.astro' import PaginationComponent from '@/components/ui/pagination' import { SITE } from '@/consts' import Layout from '@/layouts/Layout.astro' import type { PaginateFunction } from 'astro' import { type CollectionEntry, getCollection } from 'astro:content' export async function getStaticPaths({ paginate, }: { paginate: PaginateFunction }) { const allPosts = await getCollection('blog', ({ data }) => !data.draft) return paginate( allPosts.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()), { pageSize: SITE.POSTS_PER_PAGE }, ) } const { page } = Astro.props const postsByYear = page.data.reduce( (acc: Record[]>, post) => { const year = post.data.date.getFullYear().toString() ;(acc[year] ??= []).push(post) return acc }, {}, ) const years = Object.keys(postsByYear).sort((a, b) => parseInt(b) - parseInt(a)) ---
{ years.map((year) => (
{year}
    {postsByYear[year].map((post) => (
  • ))}
)) }